﻿<%@ Page Title="Documentation | NoBrainer.Sample" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Documentation.aspx.cs" Inherits="TanzimSaqib.NoBrainer.Sample.About" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <style type="text/css">
    .style1
    {
        color: #9900FF;
    }
        .style3
        {
            font-size: medium;
        }
        .style4
        {
            font-size: 9.5pt;
            font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif;
        }
    </style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<appSettings>
  <!-- Any folder path you want. A folder inside your web project is preferred. -->
  <add key="CmsXmlDirectory" value="D:\NoBrainer\NoBrainer.Sample\Content"/>
</appSettings>    <h2>
        Documentation
    </h2>
    <p>
        NoBrainer provides you with the best of both worlds: MVC pattern and built-in 
        CMS capability.</p>
    <p>
        Note: This documentation assumes that you have general idea about 
        Model-View-Controller pattern.</p>
<h2>
        <strong>Why Choose NoBrainer over ASP.NET MVC?</strong></h2>
<p>
        Converting your project into ASP.NET MVC is not always a suitable option for 
        you. There is a huge cost associated with conversion, which is in ideal case 
        totally dependant on decision from business stakeholders.
        <br />
        <br />
        On the otherhand, if you are one of the business guys and you maintain a pool of 
        developers for your project, chances are that you may want to convert your 
        project into an ASP.NET MVC project. But, when your developers become reluctant 
        to change, and to learn a whole new paradigm of development, you have no choice 
        but stick to the old WebForm, until you use NoBrainer.
    </p>
<h2>
        Easy Setup</h2>
<p>
        NoBrainer takes a novel approach - WebForm is totally rethought to use with MVC. 
        Follow the steps:</p>
<ol>
    <li>Reference <span class="style1">NoBrainer.dll </span>in your web project<span 
            class="style1">.</span></li>
    <li>Add the following in your web.config:<br />
        <br />
            <span style="font-size:
                9.5pt;font-family:Consolas;color:blue">&lt;</span><span style="font-size:9.5pt;
                font-family:Consolas;color:maroon">appSettings</span><span style="font-size:
                9.5pt;font-family:Consolas;color:blue">&gt;</span><span style="font-size:9.5pt;
                font-family:Consolas"><o:p></o:p></span><br />

            <span style="font-size:9.5pt;font-family:Consolas;color:darkgreen">&nbsp;&nbsp; &lt;!-- Any 
            folder path you want. A folder inside your web project is preferred. --&gt;</span><span 
                style="font-size:9.5pt;font-family:Consolas"><o:p></o:p></span><br />

            <span style="font-size:9.5pt;font-family:Consolas;color:blue">&nbsp;&nbsp; &lt;</span><span 
                style="font-size:9.5pt;font-family:Consolas;color:maroon">add</span><span 
                style="font-size:9.5pt;font-family:Consolas"> <span style="color:red">key</span><span 
                style="color:blue">=&quot;CmsXmlDirectory&quot;</span> <span style="color:red">value</span><span 
                style="color:blue">=&quot;D:\NoBrainer\NoBrainer.Sample\Content&quot;/&gt;</span><o:p></o:p></span><br />

            <span style="font-size:
                9.5pt;font-family:Consolas;color:blue">&lt;/</span><span style="font-size:9.5pt;
                font-family:Consolas;color:maroon">appSettings</span><span style="font-size:
                9.5pt;font-family:Consolas;color:blue">&gt;<o:p><br />
        </o:p></span><br />
    <li>
        Add this to your Global.asax:<br />
        <p class="MsoNormal">
            <span style="font-size:
9.5pt;font-family:Consolas;color:blue">void</span><span style="font-size:9.5pt;
font-family:Consolas"> Application_Start(<span style="color:blue">object</span> sender,
            <span style="color:#2B91AF">EventArgs</span> e)<o:p></o:p></span><br />
            <span style="font-size:
9.5pt;font-family:Consolas">{<o:p></o:p></span><br />
            <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
            <span style="color:green">// Ignite NoBrainer engine.</span><o:p></o:p></span>
            <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><br />
            <span style="color:#2B91AF">&nbsp;&nbsp;&nbsp; Engine</span>.Boot(() =&gt; <span style="color:blue">
            new</span> <span style="color:#2B91AF">NoCache</span>(), <o:p></o:p></span><br />

            <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color:#2B91AF">ConfigurationManager</span>.AppSettings[<span 
                style="color:#A31515">&quot;CmsXmlDirectory&quot;</span>], <span style="color:#A31515">
            &quot;xml&quot;</span>, <span style="color:#A31515">&quot;html, htm&quot;</span>);<o:p></o:p></span><br />
            <span style="font-size:
9.5pt;font-family:Consolas">}<o:p></o:p></span>
    </li>
</ol>
    <p>
        Done! Now you are free to choose which WebForm inside your project, you would 
        prefer to convert to MVC pattern.
    </p>
    <h2>
        NoBrainer makes it a breeze to make your WebForm 
        CMS-driven MVC style </h2>
    <p>
        Magic of NoBrainer is that you can very slowly start converting your project into 
        MVC. Unlike ASP.NET MVC, it does not mean you have to open a completely new 
        project and switch everything to MVC to go live. You can take one WebForm at a 
        time. Let us see how we can implement MVC in our Login.aspx page. Follow the 
        steps:</p>
    <ol>
        <li>Let&#39;s create a Model for our MVC that will be used to hold necessary data to 
            transfer back and forth from and to View and Controller. Notice that the Model 
            was derived from ModelBase which is the base class from NoBrainer to indicate 
            that the class which extends it is actually a Model.
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">public</span><span style="font-size:
9.5pt;font-family:Consolas"> <span style="color:blue">class</span> <span style="color:#2B91AF">
                AccountModel</span> : <span style="color:#2B91AF">ModelBase<br />
                </span>{<span style="mso-spacerun:yes"><br />
&nbsp;&nbsp;&nbsp; </span><span style="color:blue">public</span> <span style="color:blue">string</span> 
                UserName { <span style="color:blue">get</span>; <span style="color:blue">set</span>; 
                }<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">public</span> <span style="color:blue">string</span> 
                Password { <span style="color:blue">get</span>; <span style="color:blue">set</span>; 
                }<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">public</span> <span style="color:blue">string</span> 
                Email { <span style="color:blue">get</span>; <span style="color:blue">set</span>; 
                }<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">public</span> <span style="color:blue">bool</span> 
                PersistentCookieEnabled { <span style="color:blue">get</span>;
                <span style="color:blue">set</span>; }<br />
                }<o:p></o:p></span></p>
        </li>
        <li>Now let&#39;s create the View. Notice that the HTML tags here have several 
            highlighted non-standard attributes. Some of them matches the properties of the 
            Model that we created earlier. Ex. UserName, Password, PersistentCookieEnabled. 
            NoBrainer automatically maps these Model properties without requiring any hand 
            written code.<br />
            <br />
            Model-Error is an amazing feature that automatically maps error message sent 
            from Controller to the UI. For example, if user has typed wrong password, 
            NoBrainer will find HTML element having Model-Error = &quot;Password&quot; and update its 
            content to the error message associated with Password.<br />
            <br />
            Cms is a page level dictionary which allows you to put CMS content which come 
            from XML (we will cover that in a while).
            <br />
            <br />
            Our Model did not have ErrorMessage property. Where did it come from? Well, No 
            Brainer provides bunch of really useful extensions and default properties to 
            help you write MVC friendly WebForm. ErrorMessage is one of them, which contains 
            View-wide generic error message occured. For example: Incorrect 
            username/password combination.
            <br />
            <br />
            As you can see there is no MVC specific change in WebForm design. You can use 
            your same old WebForm practice, drag and drop controls from the Toolbox, use 
            design-view, etc. whatever you like. However, to make automatic control mapping 
            work, you will have to map Model properties. Even that&#39;s optional too, if you 
            prefer to do that WebForm way. Example: model.UserName = txtUserName.Text in 
            your code-behind file. NoBrainer gives you absolute freedom.
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas;color:darkgreen">&lt;!-- Example: Model(you can also say View)-wide 
                common error message --&gt;</span><span style="font-size:9.5pt;
font-family:Consolas"><o:p></o:p></span>
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">
                <br />
                &lt;</span><span style="font-size:9.5pt;
font-family:Consolas;color:maroon">span</span><span style="font-size:9.5pt;
font-family:Consolas"> <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
                <span style="color:red">class</span><span style="color:blue">=&quot;failureNotification&quot;</span>
                </span><span style="font-family:Consolas" class="style3"> 
                <span style="color:red"><strong>Model</strong></span></span><span style="color:blue"><span 
                    style="font-family:Consolas" class="style3"><strong>=&quot;ErrorMessage&quot;</strong></span><span style="font-size:9.5pt;
font-family:Consolas">&gt;&lt;/</span></span><span style="font-size:9.5pt;
font-family:Consolas"><span 
                    style="color:maroon">span</span><span style="color:blue">&gt;<o:p></o:p></span></span></p>
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">&lt;</span><span style="font-size:9.5pt;
font-family:Consolas;color:maroon">fieldset</span><span style="font-size:9.5pt;
font-family:Consolas"> <span style="color:red">class</span><span style="color:blue">=&quot;login&quot;&gt;</span></span><span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes"><br />
                &nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">&lt;</span><span style="color:maroon">legend</span><span 
                    style="color:blue">&gt;</span>Account Information<span style="color:blue">&lt;/</span><span 
                    style="color:maroon">legend</span><span style="color:blue">&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">&lt;</span><span style="color:maroon">p</span><span 
                    style="color:blue">&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">&lt;</span><span style="color:maroon">asp</span><span 
                    style="color:blue">:</span><span style="color:maroon">TextBox</span>
                <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
                <span style="color:red">ID</span><span style="color:blue">=&quot;UserName&quot;</span>
                <span style="color:red">CssClass</span><span style="color:blue">=&quot;textEntry&quot;</span>
                </span><span style="font-family:Consolas" class="style3">
                <span style="color:red"><strong>Model</strong></span></span><span style="color:blue"><span 
                    style="font-family:Consolas" class="style3"><strong>=&quot;UserName&quot;</strong></span><span style="font-size:
9.5pt;font-family:Consolas">&gt;&lt;/</span></span><span style="font-size:
9.5pt;font-family:Consolas"><span 
                    style="color:maroon">asp</span><span style="color:blue">:</span><span 
                    style="color:maroon">TextBox</span><span style="color:blue">&gt;</span><o:p>&nbsp;</o:p></span></p>
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:darkgreen">&lt;!-- Example: automatic error binding from 
                Model to View --&gt;</span><span style="mso-spacerun:yes"><br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">&lt;</span><span style="color:maroon">span</span>
                <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
                <span style="color:red">class</span><span style="color:blue">=&quot;failureNotification&quot;</span>
                </span>
                <span style="font-family:Consolas" class="style3">
                <span style="color:red"><strong>Model-Error</strong></span><span style="color:blue"><strong>=&quot;UserName&quot;</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas">
                <span style="color:blue">/&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">&lt;/</span><span style="color:maroon">p</span><span 
                    style="color:blue">&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">&lt;</span><span style="color:maroon">p</span><span 
                    style="color:blue">&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">&lt;</span><span style="color:maroon">asp</span><span 
                    style="color:blue">:</span><span style="color:maroon">TextBox</span>
                <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
                <span style="color:red">ID</span><span style="color:blue">=&quot;Password&quot;</span>
                <span style="color:red">CssClass</span><span style="color:blue">=&quot;passwordEntry&quot;</span>
                <span style="color:red">TextMode</span><span style="color:blue">=&quot;Password&quot;</span>
                </span>
                <span style="font-family:Consolas" class="style3">
                <span style="color:red"><strong>Model</strong></span></span><span style="color:blue"><span 
                    style="font-family:Consolas" class="style3"><strong>=&quot;Password&quot;</strong></span><span style="font-size:
9.5pt;font-family:Consolas">&gt;&lt;/</span></span><span style="font-size:
9.5pt;font-family:Consolas"><span 
                    style="color:maroon">asp</span><span style="color:blue">:</span><span 
                    style="color:maroon">TextBox</span><span style="color:blue">&gt;</span><o:p>&nbsp;</o:p></span></p>
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:darkgreen">&lt;!-- Example: 
                <br />
                </span></span>
                <span style="font-size:
9.5pt;font-family:Consolas;color:darkgreen"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>1. HTML-attribute level CMS capability
                <br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>2. Show/hide CMS driven error message by Cms-Error<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>--&gt;</span><br />
                <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">&lt;</span><span style="color:maroon">span</span>
                <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
                <span style="color:red">class</span><span style="color:blue">=&quot;</span></span><span 
                    style="font-family:Consolas" class="style3"><span 
                    style="background: yellow; mso-highlight: yellow"><strong>&lt;%</strong></span><span 
                    style="color:blue"><strong>#</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas"><span style="font-family:Consolas" class="style3"><strong> Cms[&amp;</strong><span style="color:red"><strong>quot</strong></span>;<span 
                    style="color:red"><strong>spnPasswordError</strong></span>&amp;<span style="color:red"><strong>quot</strong></span><strong>;].</strong><span 
                    style="color:red"><strong>CssClass</strong></span>
                <span style="background: yellow; mso-highlight: yellow"><strong>%&gt;</strong></span></span><span 
                    style="color:blue">&quot;</span> </span><span style="font-family:Consolas" 
                    class="style3"> <span style="color:red"><strong>Cms-Error</strong></span></span><span 
                    style="color:blue"><span style="font-family:Consolas" class="style3"><strong>=&quot;Password&quot;</strong></span><span style="font-size:
9.5pt;font-family:Consolas">&gt;</span></span><span style="font-size:
9.5pt;font-family:Consolas"><o:p></o:p></span></p>
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:darkgreen">&lt;!-- Example: strongly typed Model --&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span></span>
                <span style="font-family:Consolas" class="style3"><span style="background: yellow; mso-highlight: yellow">
                <strong>&lt;%</strong></span><span 
                    style="color:blue"><strong>#</strong></span><strong> Cms[</strong><span style="color:#A31515"><strong>&quot;spnPasswordError&quot;</strong></span><strong>].Content
                </strong>
                <span style="background: yellow; mso-highlight: yellow"><strong>%&gt;</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas"><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">&lt;/</span><span style="color:maroon">span</span><span 
                    style="color:blue">&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">&lt;/</span><span style="color:maroon">p</span><span 
                    style="color:blue">&gt;</span><o:p></o:p></span></p>
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">&lt;</span><span style="color:maroon">p</span><span 
                    style="color:blue">&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">&lt;</span><span style="color:maroon">asp</span><span 
                    style="color:blue">:</span><span style="color:maroon">CheckBox</span>
                <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
                <span style="color:red">ID</span><span style="color:blue">=&quot;RememberMe&quot;</span>
                </span>
                <span style="font-family:Consolas" class="style3">
                <span style="color:red"><strong>Model</strong></span></span><span style="color:blue"><span 
                    style="font-family:Consolas" class="style3"><strong>=&quot;PersistentCookieEnabled&quot;</strong></span><span style="font-size:
9.5pt;font-family:Consolas">/&gt;</span></span><span style="font-size:
9.5pt;font-family:Consolas"><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">&lt;</span><span style="color:maroon">asp</span><span 
                    style="color:blue">:</span><span style="color:maroon">Label</span>
                <span style="color:red">ID</span><span style="color:blue">=&quot;RememberMeLabel&quot;</span>
                <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
                <span style="color:red">AssociatedControlID</span><span style="color:blue">=&quot;RememberMe&quot;</span>
                <span style="color:red">CssClass</span><span style="color:blue">=&quot;inline&quot;&gt;</span>Keep 
                me logged in<span style="color:blue">&lt;/</span><span style="color:maroon">asp</span><span 
                    style="color:blue">:</span><span style="color:maroon">Label</span><span 
                    style="color:blue">&gt;</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">&lt;/</span><span style="color:maroon">p</span><span 
                    style="color:blue">&gt;</span><br />
                </span><span style="font-size:
9.5pt;font-family:Consolas;color:blue">&lt;/</span><span style="font-size:9.5pt;
font-family:Consolas;color:maroon">fieldset</span><span style="font-size:9.5pt;
font-family:Consolas;color:blue">&gt;<br />
                </span></p>
        </li>
        <li>Let&#39;s take a look at the code-behind of this page. First thing you are going to 
            notice is that the View does not inherit System.Web.UI.Page, rather it does from 
            ViewBase which is the base class for Views provided by NoBrainer. It takes two 
            parameters. First is the Controller name which has the driving logic for this 
            View and the Model type that the Controller and View both will be dealing with. 
            We have declared AccountModel earlier, but AccountController (our Controller) 
            will be implemented in the next step.
            <br />
            <br />
            You will also notice that there is a method named <em><strong>InvokeController</strong></em> 
            which is a native NoBrainer method inferred from ViewBase. This method allows 
            you to map View =&gt; Model and pass that Model to the designated method you have 
            written in your Controller (in here: <strong><em>Login</em></strong> is a method 
            written inside <strong><em>AccountController</em></strong>. We will see that in 
            a while.). Then the Controller method performs some actions (such as Validation, 
            etc.) and returns the modified Model to the View. The View (web layer/WebForm) 
            then examines the Model and decides what to do next. That way we leave NoBrainer 
            to do the mapping work, and seperate the logic to our Controller.
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">public</span><span style="font-size:
9.5pt;font-family:Consolas"> <span style="color:blue">partial</span> <span style="color:blue">
                class</span> <span style="color:#2B91AF">Login</span> :
                </span><span style="font-family:Consolas" class="style3"> 
                <span style="color:#2B91AF"><strong>ViewBase</strong></span>&lt;<span style="color:#2B91AF"><strong>AccountController</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas"><span style="font-family:Consolas" class="style3"><strong>,
                </strong>
                <span style="color:#2B91AF"><strong>AccountModel</strong></span></span>&gt;<br />
                {<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">protected</span> <span style="color:blue">void</span> 
                Page_Load(<span style="color:blue">object</span> sender,
                <span style="color:#2B91AF">EventArgs</span> e)<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">if</span>(IsPostBack)<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span></span><span style="font-family:Consolas" class="style3"> <strong>InvokeController(v =&gt; Controller.Login(Model));</strong></span><span style="font-size:
9.5pt;font-family:Consolas"><span 
                    style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <o:p>&nbsp;<br />
                <br />
                </o:p>
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">if</span>(</span><span 
                    style="font-family:Consolas" class="style3"><strong>Model.IsValid</strong></span><span style="font-size:
9.5pt;font-family:Consolas">)<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:#2B91AF">FormsAuthentication</span>.RedirectFromLoginPage(Model.UserName, 
                Model.PersistentCookieEnabled);<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>}<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>}<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">else</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">if</span>(Request.IsAuthenticated)<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>Response.Redirect(<span style="color:#A31515">&quot;~/Account/Manage.aspx&quot;</span>);<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>}<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>}<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>}<br />
                }<o:p><br />
                </o:p></span></p>
        </li>
        <li>Now that our Model and View are complete, let&#39;s talk about Controller. We will 
            talk everything via interfaces. Why? Because one of the advantages of using 
            interfaces is that it will allow us to make the 
            Controllers unit testable.
            <br />
            <br />
            First thing you are noticing here is that it inherits ControllerBase as well as 
            IAccountController. AccountController has to implement the method (for our case: 
            Login) that we called 
            earlier from View. As you can see it takes an instance of AccountModel, which is 
            later validated whether there&#39;s any error message and then returned the same 
            object in the end after necessary modification.<br />

            <br />
            If you need to set an error message specific to certain property (in here: 
            UserName) of the Model, you should use the Model&#39;s in-built dictionary <strong>
            <em>ErrorMessages</em></strong> to do that. However, should you require to make 
            the error message CMS driven, in other words, your business stakeholders want it 
            to hand-written by themselves outside the application, you should use the other 
            dictionary named <strong><em>CmsErrorMessages</em></strong>. You will create a 
            CMS collection which we will discuss in the last step of this tutorial, that 
            should hold a text representing <span class="style4"><strong>
                user.CmsErrorMessages[</strong><span style="color:#A31515"><strong>&quot;Password&quot;</strong></span></span>].<span style="font-size:
9.5pt;"> What this piece of code will do is it will turn on/off the text&#39;s visibility 
            (recall: <span style="color:red"><strong>Cms-Error</strong></span><span 
                    style="color:blue"><strong>=&quot;Password&quot;</strong></span>). We will 
            look at that later.<br />
            <br />
            Now about the Membership.ValidateUser and use of FormsAuthentication. You can 
            use them. That&#39;s fine! But, if you would like to make your MVC to work across 
            different form factors of computing devices such as Desktop/Mobile, you will 
            have to move it to web layer or plug it from somewhere else to make the Model 
            and Controllers device independant. Because these classes belong to ASP.NET 
            which you do not want to use in Desktop/Mobile.</span>


            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">public</span><span style="font-size:
9.5pt;font-family:Consolas"> <span style="color:blue">interface</span> </span>
            <span style="color:#2B91AF"><span class="style3" style="font-family: Consolas">
            <strong>IAccountController</strong></span><span style="font-size:
9.5pt;font-family:Consolas"><br />
            </span></span><span style="font-size:
9.5pt;font-family:Consolas">{<br />
            <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
            <span style="color:#2B91AF">AccountModel</span> Login(<span 
                style="color:#2B91AF">AccountModel</span> user);<br />
            }<o:p></o:p></span></p>
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">public</span><span style="font-size:
9.5pt;font-family:Consolas"> <span style="color:blue">class</span> <span style="color:#2B91AF">
                AccountController</span> : </span><span style="font-family: Consolas">
                <span class="style3" style="color:#2B91AF"><strong>ControllerBase</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas"><span class="style3" style="font-family: Consolas"><strong>,
                </strong></span><span style="color:#2B91AF"><span class="style3" 
                    style="font-family: Consolas"><strong>IAccountController</strong></span><br />
                </span><span style="font-size:
9.5pt;font-family:Consolas">{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">public</span> <span style="color:#2B91AF">AccountModel</span> 
                Login(<span style="color:#2B91AF">AccountModel</span> user)<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <span style="color:green">/* </span>
                <br />
                </span></span><span style="font-size:
9.5pt;font-family:Consolas;color:green"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>Example: how Models can be validated and
                <br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>error messages can be sent from Controllers.<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                */</span><span style="font-size:
9.5pt;font-family:Consolas"><o:p>&nbsp;<br />
                </o:p>
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <span style="color:green">// Example: how error messages can be set from the 
                Controllers </span>
                <br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">if</span> (<span style="color:blue">string</span>.IsNullOrEmpty(user.UserName))<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span></span><span class="style3" style="font-family: Consolas"><strong>
                user.ErrorMessages[</strong><span style="color:#A31515"><strong>&quot;UserName&quot;</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas">] = <span style="color:#A31515">&quot;UserName cannot be empty.&quot;</span>;<o:p></o:p></span></p>
            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:green">// Example: how to enable/disable CMS based 
                error messages to the UI</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">if</span> (<span style="color:blue">string</span>.IsNullOrEmpty(user.Password))<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span></span><span class="style3" style="font-family: Consolas"><strong>
                user.CmsErrorMessages[</strong><span style="color:#A31515"><strong>&quot;Password&quot;</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas">] = <span style="color:blue">true</span>;<span 
                    style="mso-spacerun:yes"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">if</span>(<span 
                    style="color:blue">string</span>.IsNullOrEmpty(user.UserName) ||
                <span style="color:blue">string</span>.IsNullOrEmpty(user.Password))<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                {<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span></span><span class="style3" style="font-family: Consolas"><strong>
                user.ErrorMessage</strong></span><span style="font-size:
9.5pt;font-family:Consolas"> = <span style="color:#A31515">&quot;There are errors. Please fix them 
                and try again.&quot;</span>;<span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">else</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">if</span> (!</span><span class="style3" 
                    style="font-family: Consolas"><span style="color:#2B91AF"><strong>Membership</strong></span><strong>.ValidateUser(user.UserName, 
                user.Password)</strong></span><span style="font-size:
9.5pt;font-family:Consolas">)<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>user.ErrorMessage = <span style="color:#A31515">&quot;UserName/Password 
                combination is incorrect.&quot;</span>;<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>}<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span><span style="color:blue">else</span><br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>{<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span></span><span style="font-family: Consolas"><span class="style3" 
                    style="color:#2B91AF"><strong>FormsAuthentication</strong></span></span><span style="font-size:
9.5pt;font-family:Consolas"><span class="style3" style="font-family: Consolas"><strong>.SetAuthCookie</strong></span>(user.UserName, 
                user.PersistentCookieEnabled);<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>user.IsValid = <span style="color:blue">true</span>;<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>}<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                }<o:p>&nbsp;<br />
                </o:p>
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <span style="color:blue">return</span> user;<br />
                <span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>}<br />
                }<o:p><br />
                </o:p>
                </span>
            </p>
        </li>
        <li>That&#39;s it! Oh, one last thing, because this View (as we have written) requires 
            us to define a CMS variable &quot;spnPasswordError&quot; (see View HTML) for this particular View, we need to 
            define it inside our <em><strong>Content </strong></em>(move to the beginning of 
            this document where we defined <span 
                style="font-size:9.5pt;font-family:Consolas"> <span 
                style="color:blue">CmsXmlDirectory</span></span>) folder.&nbsp; Let&#39;s create 
            TanzimSaqib.NoBrainer.Sample.Controllers.StaticPageController.xml, which matches 
            the Controller namespace we have in this project. This namespace mapping is important. 
            Put the following XML inside of that.<br />
            <br />
            As you can see this XML file contains all possible Views that 
            this Controller can handle. 
            For our example of Login screen, we are specifying our View page path as 
            Account\Login.aspx, inside of that we are defining our CMS variable 
            spnPasswordError, its cssClass as well as the content. These data are modifiable 
            as CMS data as well as injected while rendering the page by NoBrainer.

            <p class="MsoNormal">
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">&lt;?</span><span style="font-size:9.5pt;
font-family:Consolas;color:#A31515">xml</span><span style="font-size:9.5pt;
font-family:Consolas;color:blue"> </span>
                <span style="font-size:9.5pt;
font-family:Consolas;color:red">version</span><span style="font-size:9.5pt;
font-family:Consolas;color:blue">=</span><span style="font-size:9.5pt;
font-family:Consolas">&quot;<span style="color:blue">1.0</span>&quot;<span style="color:blue"> </span>
                <span style="color:red">encoding</span><span style="color:blue">=</span>&quot;<span 
                    style="color:blue">utf-8</span>&quot;<span style="color:blue"> ?&gt;</span><br />
                </span><span style="font-size:
9.5pt;font-family:Consolas;color:blue">&lt;!--</span><span style="font-size:
9.5pt;font-family:Consolas;color:green"> Example of content injection aka CMS capability </span>
                <span style="font-size:9.5pt;font-family:Consolas;color:blue">--&gt;</span><br />
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">&lt;</span><span style="font-size:9.5pt;
font-family:Consolas;color:#A31515">Views</span><span style="font-size:9.5pt;
font-family:Consolas;color:blue">&gt;</span><br />
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue"><span style="mso-spacerun:yes">&nbsp; </span>&lt;</span><span 
                    style="font-size:9.5pt;font-family:Consolas;color:#A31515">View</span><span 
                    style="font-size:9.5pt;font-family:Consolas;color:blue"> </span>
                <span style="font-family:Consolas;color:red" class="style3"><strong>pageName</strong></span><span 
                    style="font-family:Consolas;color:blue" class="style3"><strong>=</strong></span><span 
                    style="font-size:9.5pt;font-family:Consolas"><strong>&quot;</strong></span><span 
                    style="font-family:Consolas"><span style="color:blue" class="style3"><strong>Account\Login.aspx</strong></span></span><span 
                    style="font-size:9.5pt;font-family:Consolas">&quot;<span 
                    style="color:blue">&gt;</span><br />
                </span><span style="font-size:
9.5pt;font-family:Consolas;color:blue"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
                &lt;</span><span style="font-size:9.5pt;font-family:Consolas;color:#A31515">Content</span><span 
                    style="font-size:9.5pt;font-family:Consolas;color:blue"> </span>
                <span style="font-family:Consolas;color:red" class="style3"><strong>id</strong></span><span 
                    style="font-family:Consolas;color:blue" class="style3"><strong>=</strong></span><span 
                    style="font-size:9.5pt;font-family:Consolas"><strong>&quot;</strong></span><span 
                    style="font-family:Consolas"><span style="color:blue" class="style3"><strong>spnPasswordError</strong></span></span><span 
                    style="font-size:9.5pt;font-family:Consolas">&quot;<span 
                    style="color:blue"> </span>
                </span><span 
                    style="font-family:Consolas" class="style3"><span style="color:red"><strong>cssClass</strong></span><span 
                    style="color:blue"><strong>=</strong></span>&quot;<span style="color:blue"><strong>failureNotification</strong></span>&quot;<span 
                    style="color:blue"><strong>&gt;</strong></span></span><span 
                    style="font-size:9.5pt;font-family:Consolas"><span 
                    style="font-family:Consolas" class="style3"><strong>Password cannot be empty.</strong></span><span 
                    style="color:blue">&lt;/</span><span style="color:#A31515">Content</span><span 
                    style="color:blue">&gt;</span><br />
                </span><span style="font-size:
9.5pt;font-family:Consolas;color:blue"><span style="mso-spacerun:yes">&nbsp; </span>&lt;/</span><span style="font-size:9.5pt;font-family:Consolas;
color:#A31515">View</span><span style="font-size:9.5pt;font-family:Consolas;
color:blue">&gt;</span><br />
                <span style="font-size:
9.5pt;font-family:Consolas;color:blue">&lt;/</span><span style="font-size:9.5pt;
font-family:Consolas;color:#A31515">Views</span><span style="font-size:9.5pt;
font-family:Consolas;color:blue">&gt;</span></p>
        </li>
    </ol>
    <p>
        That way you make your logic seperate from the UI layer, which also makes it unit testable, and deployable to many different form factors of computing devices. It also facilitates the power of CMS. You do not have to give business stakeholders full freedom on your code. Just give them FTP access to the Content folder if you will, and they will take it from there. They will never call you up at the dead night to make some changes to the content just because that's important to their business, rather they could do it by themselves. 
    </p>
</asp:Content>
